﻿//importJS("libs/api.js");

var lan = {
    message: {
        ajaxError: '请求失败',
        ajaxTimeout: '请求超时',
        show: {
            title:'提示'
        },
        alert: {
            title: '提示'
        },
        confirm: {
            title: '确认'
        },
    }
};

var formStyle = {
    width: 300,
    labelAlign: 'left',
    panelHeight:'auto'
}

/**
 * jeasyui数据的验证
 * */
$.extend($.fn.validatebox.defaults.rules, {
    CHS: {
        validator: function (value, param) {
            return /^[\u0391-\uFFE5]+$/.test(value);
        },
        message: '请输入汉字'
    },
    ZIP: {
        validator: function (value, param) {
            return /^[1-9]\d{5}$/.test(value);
        },
        message: '邮政编码不存在'
    },
    QQ: {
        validator: function (value, param) {
            return /^[1-9]\d{4,10}$/.test(value);
        },
        message: 'QQ号码不正确'
    },
    mobile: {
        validator: function (value, param) {
            return /^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[1-478])\d{8}$/.test(value);
        },
        message: '手机号码不正确'
    },
    money: {
        validator: function (value, param) {
            return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(value);
        },
        message: '请输入正确的金额'
    },
    decimal: {
        validator: function (value, param) {
            return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(value);
        },
        message: '请输入正确的数字'
    },
    carNO: {
        validator: function (value, param) {
            var re = /^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$/;
            return re.test(value);
        },
        message: '请输入正确的车牌号'
    },
    telephone: {
        validator: function (value, param) {
            return /(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^((\(\d{3}\))|(\d{3}\-))?(1[3578]\d{9}))$/.test(value);
            //return /^\d+$/.test(value);
        },
        message: '联系电话不正确'
    },
    date: {
        validator: function (value) { //格式yyyy-MM-dd或yyyy-M-d 
            return /^(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29))$)|(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))$/i.test(value);
        },
        message: '请输入正确的日期格式,应为yyyy-MM-dd或yyyy-M-d'
    },
    username: {
        validator: function (value) {
            value = value.replace(" ", "");
            return /^[a-zA-Z][a-zA-Z0-9_]{2,19}$/i.test(value);
        },
        message: '用户名不合法（允许3-20个字，开头必须是英文字母，而其他字则允许输入字母、数字及下划线符号）'
    },
    loginName: {
        validator: function (value, param) {
            //value = value.replace(" ", "");
            return /^[\u0391-\uFFE5\w]+$/.test(value);
        },
        message: '登录名称只允许汉字、英文字母、数字及下划线。'
    },
    safepass: {
        validator: function (value, param) {
            return safePassword(value);
        },
        message: '密码由字母和数字组成，至少4位'
    },
    equals: {
        validator: function (value, param) {
            return value == $(param[0]).val();
        },
        message: '两次输入的内容不一致'
    },
    number: {
        validator: function (value, param) {
            return /^\d+$/.test(value);
        },
        message: '请输入数字'
    },
    range: {
        validator: function (value, param) {
            if (/^0|[1-9]\d*$/.test(value)) {
                return value >= param[0] && value <= param[1]
            } else {
                return false;
            }
        },
        message: '输入的数字在{0}到{1}之间'
    },
    idcard: {
        validator: function (value, param) {

            return checkCard(value);
        },
        message: '请输入正确的身份证号码'
    },
    address: {
        validator: function (value, param) {
            value = value.replace(" ", "");
            return /^[\u0391-\uFFE5\w]{2,49}$/.test(value);
        },
        message: '请输入正确的地址,长度在2-50个字'
    },
    username: {
        validator: function (value) {
            //value = value.replace(" ", "");
            return /^[a-zA-Z][a-zA-Z0-9_]{1,19}$/i.test(value);
        },
        message: '帐号不合法（允许2-20个字符，开头必须是英文字母，而其他字符则允许输入字母、数字及底线符号）'
    },
    Longtitude: {
        validator: function (value) {
            return /^-?(?:(?:180(?:\.0{1,5})?)|(?:(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d{1,5})?))$/.test(value);
        },
        message: '请输入正确的经度值'
    },
    Latitude: {
        validator: function (value) {
            return /^-?(?:90(?:\.0{1,5})?|(?:[1-8]?\d(?:\.\d{1,5})?))$/.test(value);
        },
        message: '请输入正确的纬度值'
    },
    LoginIdIsExist: {
        validator: function (value, param) {
            var loginID = (value).toLowerCase();
            var resultData = {
                status: true,
            };
            
            globalAjax.userLoginIdIsExist({ U_LOGINNAME: loginID }, function (res) {
                if (res.code == ResponseCode.OK) {
                    resultData.status = res.data == 0;
                }
            },false);

            return resultData.status;
        },
        message: '用户名已经存在，请重新输入。'
    }
});

/* 密码由字母和数字组成，至少6位 */
var safePassword = function (value) {
    return !(/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,3})$|\s/.test(value));
}

var vcity = {
    11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古",
    21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏",
    33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南",
    42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆",
    51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃",
    63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外"
};

var checkCard = function (card) {
    //是否为空  
    if (card === '') return false;

    //校验长度，类型  
    if (isCardNo(card) === false) return false;
    //检查省份  
    if (checkProvince(card) === false) return false;
    //校验生日  
    if (checkBirthday(card) === false) return false;
    //检验位的检测  
    if (checkParity(card) === false) return false;

    return true;
};

var getSex = function (card) {
    if (checkCard(card)) {
        if (card.length == 15) {
            return card.substring(14, 15) % 2 == 0 ? '女' : '男';
        } else if (card.length == 18) {
            return card.substring(14, 17) % 2 == 0 ? '女' : '男';
        }
    }
}

var getBirthday = function (card) {
    if (checkCard(card)) {
        if (card.length == 15) {
            var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
            var arr_data = card.match(re_fifteen);
            var year = arr_data[2];
            var month = arr_data[3];
            var day = arr_data[4];
            var birthday = '19' + year + '-' + month + '-' + day;
            return birthday;
        } else if (card.length == 18) {
            var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
            var arr_data = card.match(re_eighteen);
            var year = arr_data[2];
            var month = arr_data[3];
            var day = arr_data[4];
            var birthday = year + '-' + month + '-' + day;
            return birthday;
        }
    }
}



//检查号码是否符合规范，包括长度，类型  
var isCardNo = function (card) {
    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
    var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
    if (reg.test(card) === false) {
        return false;
    }
    return true;
};

//取身份证前两位,校验省份  
var checkProvince = function (card) {
    var province = card.substr(0, 2);
    if (vcity[province] == undefined) {
        return false;
    }
    return true;
};

//检查生日是否正确  
var checkBirthday = function (card) {
    var len = card.length;
    //身份证15位时，次序为省（3位）市（3位）年（2位）月（2位）日（2位）校验位（3位），皆为数字  
    if (len == '15') {
        var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
        var arr_data = card.match(re_fifteen);
        var year = arr_data[2];
        var month = arr_data[3];
        var day = arr_data[4];
        var birthday = new Date('19' + year + '/' + month + '/' + day);
        return verifyBirthday('19' + year, month, day, birthday);
    }
    //身份证18位时，次序为省（3位）市（3位）年（4位）月（2位）日（2位）校验位（4位），校验位末尾可能为X  
    if (len == '18') {
        var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
        var arr_data = card.match(re_eighteen);
        var year = arr_data[2];
        var month = arr_data[3];
        var day = arr_data[4];
        var birthday = new Date(year + '/' + month + '/' + day);
        return verifyBirthday(year, month, day, birthday);
    }
    return false;
};

//校验日期  
var verifyBirthday = function (year, month, day, birthday) {
    var now = new Date();
    var now_year = now.getFullYear();
    //年月日是否合理  
    if (birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day) {
        //判断年份的范围（3岁到100岁之间)  
        var time = now_year - year;
        if (time >= 3 && time <= 100) {
            return true;
        }
        return false;
    }
    return false;
};

//校验位的检测  
var checkParity = function (card) {
    //15位转18位  
    card = changeFivteenToEighteen(card);
    var len = card.length;
    if (len == '18') {
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
        var cardTemp = 0, i, valnum;
        for (i = 0; i < 17; i++) {
            cardTemp += card.substr(i, 1) * arrInt[i];
        }
        valnum = arrCh[cardTemp % 11];
        if (valnum == card.substr(17, 1)) {
            return true;
        }
        return false;
    }
    return false;
};

//15位转18位身份证号  
var changeFivteenToEighteen = function (card) {
    if (card.length == '15') {
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
        var cardTemp = 0, i;
        card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);
        for (i = 0; i < 17; i++) {
            cardTemp += card.substr(i, 1) * arrInt[i];
        }
        card += arrCh[cardTemp % 11];
        return card;
    }
    return card;
};

var isDateTime = function (format, reObj) {
    format = format || 'yyyy-MM-dd';
    var input = this, o = {}, d = new Date();
    var f1 = format.split(/[^a-z]+/gi), f2 = input.split(/\D+/g), f3 = format.split(/[a-z]+/gi), f4 = input.split(/\d+/g);
    var len = f1.length, len1 = f3.length;
    if (len != f2.length || len1 != f4.length) return false;
    for (var i = 0; i < len1; i++) if (f3[i] != f4[i]) return false;
    for (var i = 0; i < len; i++) o[f1[i]] = f2[i];
    o.yyyy = s(o.yyyy, o.yy, d.getFullYear(), 9999, 4);
    o.MM = s(o.MM, o.M, d.getMonth() + 1, 12);
    o.dd = s(o.dd, o.d, d.getDate(), 31);
    o.hh = s(o.hh, o.h, d.getHours(), 24);
    o.mm = s(o.mm, o.m, d.getMinutes());
    o.ss = s(o.ss, o.s, d.getSeconds());
    o.ms = s(o.ms, o.ms, d.getMilliseconds(), 999, 3);
    if (o.yyyy + o.MM + o.dd + o.hh + o.mm + o.ss + o.ms < 0) return false;
    if (o.yyyy < 100) o.yyyy += (o.yyyy > 30 ? 1900 : 2000);
    d = new Date(o.yyyy, o.MM - 1, o.dd, o.hh, o.mm, o.ss, o.ms);
    var reVal = d.getFullYear() == o.yyyy && d.getMonth() + 1 == o.MM && d.getDate() == o.dd && d.getHours() == o.hh && d.getMinutes() == o.mm && d.getSeconds() == o.ss && d.getMilliseconds() == o.ms;
    return reVal && reObj ? d : reVal;
    function s(s1, s2, s3, s4, s5) {
        s4 = s4 || 60, s5 = s5 || 2;
        var reVal = s3;
        if (s1 != undefined && s1 != '' || !isNaN(s1)) reVal = s1 * 1;
        if (s2 != undefined && s2 != '' && !isNaN(s2)) reVal = s2 * 1;
        return (reVal == s1 && s1.length != s5 || reVal > s4) ? -10000 : reVal;
    }
};

Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

function formatHourTime(val) {
    if (val) {
        var re = /-?\d+/;
        var m = re.exec(val);
        var d = new Date(parseInt(m[0]));
        // 按【2012-02-13 09:09:09】的格式返回日期
        return d.format("hh:mm:ss");
    }
    return val;
}

function formatTime(val) {

    if ((val + '').length == 10) {
        val = val + '000';
    }

    if (val) {
        var re = /-?\d+/;
        var m = re.exec(val);
        var d = new Date(parseInt(m[0]));
        // 按【2012-02-13 09:09:09】的格式返回日期
        return d.format("yyyy-MM-dd hh:mm:ss");
    }
    return val;
}

function formatDate(val) {

    if ((val + '').length == 10) {
        val = val + '000';
    }

    if (val) {
        var re = /-?\d+/;
        var m = re.exec(val);
        var d = new Date(parseInt(m[0]));
        // 按【2012-02-13】的格式返回日期
        return d.format("yyyy-MM-dd");
    }
    return val;
}

function formatHous(val) {
    var intVal = parseInt(val)
    if (intVal == val) {
        return intVal + '点';
    }
    return intVal + '点半';
}

function toHourMinute(minutes) {
    var hm = "";
    var hours = (Math.floor(minutes / 60));
    if (hours > 0)
        hm += hours + "小时";
    hm += (minutes % 60) + "分钟";
    return hm;
}




function _arrayBufferToBase64(buffer) {
    var binary = '';
    var bytes = new Uint8Array(buffer);
    var len = bytes.byteLength;
    for (var i = 0; i < len; i++) {
        binary += String.fromCharCode(bytes[i]);
    }
    return window.btoa(binary);
}

var userAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used 
jQuery.browser = {
    version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
    safari: /webkit/.test(userAgent),
    opera: /opera/.test(userAgent),
    msie: /(msie\s|trident\/7)([\w.]+)/.test(userAgent) && !/opera/.test(userAgent),
    mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
};

function conveterParamsToJson(paramsAndValues) {
    var jsonObj = {};
    for (var i = 0; paramsAndValues != null && i < paramsAndValues.length; i++) {
        var para = paramsAndValues[i];
        jsonObj[para.name] = para.value;
    }
    return jsonObj;
}

/**
 ** 加法函数，用来得到精确的加法结果
 ** 说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
 ** 调用：accAdd(arg1,arg2)
 ** 返回值：arg1加上arg2的精确结果
 **/
function accAdd(arg1, arg2) {
    var r1, r2, m, c;
    try {
        r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
        r1 = 0;
    }
    try {
        r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
        r2 = 0;
    }
    c = Math.abs(r1 - r2);
    m = Math.pow(10, Math.max(r1, r2));
    if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", "")) * cm;
        } else {
            arg1 = Number(arg1.toString().replace(".", "")) * cm;
            arg2 = Number(arg2.toString().replace(".", ""));
        }
    } else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
    }
    return (arg1 + arg2) / m;
}

//给Number类型增加一个add方法，调用起来更加方便。
Number.prototype.add = function (arg) {
    return accAdd(arg, this);
};

/**
 ** 减法函数，用来得到精确的减法结果
 ** 说明：javascript的减法结果会有误差，在两个浮点数相减的时候会比较明显。这个函数返回较为精确的减法结果。
 ** 调用：accSub(arg1,arg2)
 ** 返回值：arg1加上arg2的精确结果
 **/
function accSub(arg1, arg2) {
    var r1, r2, m, n;
    try {
        r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
        r1 = 0;
    }
    try {
        r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
        r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

// 给Number类型增加一个mul方法，调用起来更加方便。
Number.prototype.sub = function (arg) {
    return accSub(arg, this);
};

var UserContol = function () {
    this.dataGrid = {
        id: '',
        title: '',
        url: '',
        notEmpty: 1,
        queryParams: {},
        idField: '',
        sortName: '',
        sortOrder: 'desc',
        fit: true,
        striped: true,
        singleSelect: true,
        pagination: true,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        rownumbers: true,
        toolbar: [],
        frozenColumns: [],
        columns: [],
        isTop: false,
        remoteSort: true,
        groupField: '',
        showFooter: false,
        groupFormatter: function () { },
        rowStyler: function () { },
        loader: function () { },
        onSelect: function () { },
        onDblClickRow: function () { },
        onClickCell: function () { },
        onClickRow: function () { },
        onRowContextMenu: function () { },
        onLoadSuccess: function () { },
        onBeforeLoad: function () { },
        datagrid: function () { }
    }

    this.InitdataGrid = function () {
        if (this.dataGrid.isTop) {
            top.$('#' + this.dataGrid.id).datagrid({
                title: this.dataGrid.title,
                url: this.dataGrid.url,
                queryParams: this.dataGrid.queryParams,
                idField: this.dataGrid.idField,
                sortName: this.dataGrid.sortName,
                sortOrder: this.dataGrid.sortOrder,
                fit: this.dataGrid.fit,
                striped: this.dataGrid.striped,
                pagination: this.dataGrid.pagination,
                pageSize: this.dataGrid.pageSize,
                pageList: this.dataGrid.pageList,
                rownumbers: this.dataGrid.rownumbers,
                checkOnSelect: this.dataGrid.checkOnSelect,
                selectOnCheck: this.dataGrid.selectOnCheck,
                onCheckAll: this.dataGrid.onCheckAll,
                onUncheckAll: this.dataGrid.onUncheckAll,
                toolbar: this.dataGrid.toolbar,
                singleSelect: this.dataGrid.singleSelect,
                remoteSort: this.dataGrid.remoteSort,
                groupField: this.dataGrid.groupField,
                groupFormatter: this.dataGrid.groupFormatter,
                rowStyler: this.dataGrid.rowStyler,
                loader: this.dataGrid.loader,
                frozenColumns: this.dataGrid.frozenColumns,
                columns: this.dataGrid.columns,
                onSelect: this.dataGrid.onSelect,
                onDblClickRow: this.dataGrid.onDblClickRow,
                onClickCell: this.dataGrid.onClickCell,
                onClickRow: this.dataGrid.onClickRow,
                onRowContextMenu: this.dataGrid.onRowContextMenu,
                onLoadSuccess: this.dataGrid.onLoadSuccess,
                onBeforeLoad: this.dataGrid.onBeforeLoad,
                showFooter: this.dataGrid.showFooter,
                datagrid: this.dataGrid.datagrid
            })
        } else {
            $('#' + this.dataGrid.id).datagrid({
                title: this.dataGrid.title,
                url: this.dataGrid.url,
                queryParams: this.dataGrid.queryParams,
                idField: this.dataGrid.idField,
                sortName: this.dataGrid.sortName,
                sortOrder: this.dataGrid.sortOrder,
                fit: this.dataGrid.fit,
                striped: this.dataGrid.striped,
                pagination: this.dataGrid.pagination,
                pageSize: this.dataGrid.pageSize,
                pageList: this.dataGrid.pageList,
                rownumbers: this.dataGrid.rownumbers,
                checkOnSelect: this.dataGrid.checkOnSelect,
                selectOnCheck: this.dataGrid.selectOnCheck,
                onCheckAll: this.dataGrid.onCheckAll,
                onUncheckAll: this.dataGrid.onUncheckAll,
                toolbar: this.dataGrid.toolbar,
                singleSelect: this.dataGrid.singleSelect,
                remoteSort: this.dataGrid.remoteSort,
                groupField: this.dataGrid.groupField,
                groupFormatter: this.dataGrid.groupFormatter,
                rowStyler: this.dataGrid.rowStyler,
                loader: this.dataGrid.loader,
                frozenColumns: this.dataGrid.frozenColumns,
                columns: this.dataGrid.columns,
                onSelect: this.dataGrid.onSelect,
                onDblClickRow: this.dataGrid.onDblClickRow,
                onClickCell: this.dataGrid.onClickCell,
                onClickRow: this.dataGrid.onClickRow,
                onRowContextMenu: this.dataGrid.onRowContextMenu,
                onLoadSuccess: this.dataGrid.onLoadSuccess,
                onBeforeLoad: this.dataGrid.onBeforeLoad,
                showFooter: this.dataGrid.showFooter,
                datagrid: this.dataGrid.datagrid
            })
        }
    }

    this.treeGrid = {
        id: '',
        title: '',
        url: '',
        idField: '',
        treeField: '',
        fit: true,
        animate: true,
        collapsible: true,
        striped: true,
        rownumbers: true,
        singleSelect: true,
        method: 'post',
        toolbar: [],
        columns: [],
        onLoadError: function () { },
        loader: function () { }
    }

    this.InittreeGrid = function () {
        $('#' + this.treeGrid.id).treegrid({
            title: this.treeGrid.title,
            url: this.treeGrid.url,
            idField: this.treeGrid.idField,
            treeField: this.treeGrid.treeField,
            fit: this.treeGrid.fit,
            animate: this.treeGrid.animate,
            collapsible: this.treeGrid.collapsible,
            striped: this.treeGrid.striped,
            rownumbers: this.treeGrid.rownumbers,
            singleSelect: this.treeGrid.singleSelect,
            toolbar: this.treeGrid.toolbar,
            columns: this.treeGrid.columns,
            loader: this.treeGrid.loader,
            onLoadError: this.treeGrid.onLoadError
        })
    }

    this.window = {
        id: '',
        modal: true,
        shadow: true,
        closed: true,
        resizable: false,
        width: 780,
        height: 240,
        top: 80,
        left: 80
    }

    this.InitWindow = function () {
        $('#' + this.window.id).window({
            modal: this.window.modal,
            shadow: this.window.shadow,
            closed: this.window.closed,
            resizable: this.window.resizable,
            width: this.window.width,
            height: this.window.height,
            top: this.window.top,
            left: this.window.left
        });
        $('#' + this.window.id).window();
    }

    //分组Grid
    this.dataGridView = {
        id: '',
        title: '',
        url: '',
        notEmpty: 1,
        queryParams: {},
        idField: '',
        sortName: '',
        sortOrder: 'desc',
        fit: true,
        striped: true,
        singleSelect: true,
        pagination: true,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        rownumbers: true,
        toolbar: [],
        frozenColumns: [],
        columns: [],
        isTop: false,
        remoteSort: true,
        groupField: '',
        showFooter: false,
        groupFormatter: function () { },
        view: '',
        detailFormatter: function () { },
        onExpandRow: function () { },
        rowStyler: function () { },
        onSelect: function () { },
        onDblClickRow: function () { },
        onClickCell: function () { },
        onClickRow: function () { },
        onRowContextMenu: function () { },
        onLoadSuccess: function () { },
        onBeforeLoad: function () { },
        datagrid: function () { }
    }

    this.InitdataGridView = function () {
        if (this.dataGridView.isTop) {
            top.$('#' + this.dataGridView.id).datagrid({
                title: this.dataGridView.title,
                url: this.dataGridView.url,
                queryParams: this.dataGridView.queryParams,
                idField: this.dataGridView.idField,
                sortName: this.dataGridView.sortName,
                sortOrder: this.dataGridView.sortOrder,
                fit: this.dataGridView.fit,
                striped: this.dataGridView.striped,
                pagination: this.dataGridView.pagination,
                pageSize: this.dataGridView.pageSize,
                pageList: this.dataGridView.pageList,
                rownumbers: this.dataGridView.rownumbers,
                checkOnSelect: this.dataGridView.checkOnSelect,
                selectOnCheck: this.dataGridView.selectOnCheck,
                onCheckAll: this.dataGridView.onCheckAll,
                onUncheckAll: this.dataGridView.onUncheckAll,
                toolbar: this.dataGridView.toolbar,
                singleSelect: this.dataGridView.singleSelect,
                remoteSort: this.dataGridView.remoteSort,
                groupField: this.dataGridView.groupField,
                groupFormatter: this.dataGridView.groupFormatter,
                view: this.dataGridView.view,
                detailFormatter: this.dataGridView.detailFormatter,
                onExpandRow: this.dataGridView.onExpandRow,
                rowStyler: this.dataGridView.rowStyler,
                frozenColumns: this.dataGridView.frozenColumns,
                columns: this.dataGridView.columns,
                onSelect: this.dataGridView.onSelect,
                onDblClickRow: this.dataGridView.onDblClickRow,
                onClickCell: this.dataGridView.onClickCell,
                onClickRow: this.dataGridView.onClickRow,
                onRowContextMenu: this.dataGridView.onRowContextMenu,
                onLoadSuccess: this.dataGridView.onLoadSuccess,
                onBeforeLoad: this.dataGridView.onBeforeLoad,
                showFooter: this.dataGridView.showFooter,
                datagrid: this.dataGridView.datagrid
            })
        } else {
            $('#' + this.dataGridView.id).datagrid({
                title: this.dataGridView.title,
                url: this.dataGridView.url,
                queryParams: this.dataGridView.queryParams,
                idField: this.dataGridView.idField,
                sortName: this.dataGridView.sortName,
                sortOrder: this.dataGridView.sortOrder,
                fit: this.dataGridView.fit,
                striped: this.dataGridView.striped,
                pagination: this.dataGridView.pagination,
                pageSize: this.dataGridView.pageSize,
                pageList: this.dataGridView.pageList,
                rownumbers: this.dataGridView.rownumbers,
                checkOnSelect: this.dataGridView.checkOnSelect,
                selectOnCheck: this.dataGridView.selectOnCheck,
                onCheckAll: this.dataGridView.onCheckAll,
                onUncheckAll: this.dataGridView.onUncheckAll,
                toolbar: this.dataGridView.toolbar,
                singleSelect: this.dataGridView.singleSelect,
                remoteSort: this.dataGridView.remoteSort,
                groupField: this.dataGridView.groupField,
                groupFormatter: this.dataGridView.groupFormatter,
                view: this.dataGridView.view,
                detailFormatter: this.dataGridView.detailFormatter,
                onExpandRow: this.dataGridView.onExpandRow,
                rowStyler: this.dataGridView.rowStyler,
                frozenColumns: this.dataGridView.frozenColumns,
                columns: this.dataGridView.columns,
                onSelect: this.dataGridView.onSelect,
                onDblClickRow: this.dataGridView.onDblClickRow,
                onClickCell: this.dataGridView.onClickCell,
                onClickRow: this.dataGridView.onClickRow,
                onRowContextMenu: this.dataGridView.onRowContextMenu,
                onLoadSuccess: this.dataGridView.onLoadSuccess,
                onBeforeLoad: this.dataGridView.onBeforeLoad,
                showFooter: this.dataGridView.showFooter,
                datagrid: this.dataGridView.datagrid
            })
        }
    }
}

function dialogGuid() {
    var s4 = function () {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    };
    return "homepoker-" + (s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4());
}
/**
 对话框的封装 
 */
$.hDialog = function (options) {
    options = $.extend({}, $.hDialog.defaults, options || {});

    var dialogId = dialogGuid();
    if (options.id)
        dialogId = options.id;

    var defaultBtn = [{
        text: button.sure,
        //width: '100px',
        handler: options.submit
    },
    {
        text: button.cancel,
        //width: '100px',
        handler: function () {
            $("#" + dialogId).dialog("close");
        }
    }];

    if (!options.showBtns)
        defaultBtn = [];

    if (options.buttons.length == 0)
        options.buttons = defaultBtn;

    if (options.max) {
        var winWidth = $(window).width();
        var winHeight = $(window).height();
        options.width = winWidth - 20;
        options.height = winHeight - 20;
    }
    if (options.onLoad) {
        var loadDialog = options.onLoad;
        options.onLoad = function () {
            loadDialog();
            $(this).find("input:visible").eq(0).focus();
        }
    }
    else {
        $(this).find("input:visible").eq(0).focus();
    }
    var $dialog = $('<div/>').css('padding', options.boxPadding).appendTo($('body'));

    var dialog = $dialog.dialog($.extend(options, {
        onClose: function () {
            dialog.dialog('destroy');
        }
    })).attr('id', dialogId);
    $dialog.find('.dialog-button').css('text-align', options.align);
    return dialog;
};

$.hDialog.defaults = $.extend({}, $.fn.dialog.defaults, {
    boxPadding: '3px',
    align: 'right', //按钮对齐方式
    href: '',
    id: '',
    content: '',
    height: 200,
    width: 400,
    collapsible: false,
    minimizable: false,
    maximizable: false,
    closable: true,
    modal: true,
    shadow: false,
    mask: true,
    cache: false,
    closed: false,//默认是否关闭窗口 如果为true,需调用open方法打开
    showBtns: true,
    draggable: true,//不允许移动对话框
    buttons: [],
    onBeforeOpen: function () {

    },
    submit: function () {
        alert('写入可执行代码');
        return false;
    },
    onBeforeClose: function () {
        $(this).find(".combo-f").each(function () {
            var panel = $(this).data().combo.panel;
            panel.panel("destroy");
        });
        $(this).empty();
    },
    onMove: function (left, right) {
        $('.validatebox-tip').remove();
    },
    onLoad: function () {
        if (top.$("#form") != undefined) {
            setControlEditStatus(top.$("#form"));
        }
    }
});

function setControlEditStatus(editForm) {
    var items = editForm.serializeArray();
    for (var o in items) {
        var ctlId = items[o].name;
        var ctl = top.$("#" + ctlId);

        //如果没有找到控件，那么用name再去找一次控件
        if (ctl[0] == undefined) {
            ctl = top.$('input[name=' + ctlId + ']');
            var cssName = ctl[0].className;
            var cssArgs = cssName.split(' ');
            if (cssArgs[0] == 'txt00') {
                top.$('input[name=' + ctlId + ']').attr("disabled", "disabled");
            }
        }
        else {
            var cssName = ctl.attr('class');
            if (cssName != undefined) {
                var cssArgs = cssName.split(' ');
                if (cssArgs[0] == 'txt00') {
                    //不能进行修改的控件
                    var ctlType = cssArgs[1];
                    switch (ctlType) {
                        case 'easyui-textbox':
                            ctl.textbox('readonly', true);
                            break;
                        case 'easyui-numberspinner':
                            ctl.textbox('readonly', true);
                            break;
                        case 'easyui-combobox':
                            ctl.textbox('readonly', true);
                            break;
                        case 'easyui-numberbox':
                            ctl.textbox('readonly', true);
                            break;
                        default:
                            //判断是不是传统控件
                            top.$("#" + ctlId).attr("disabled", "disabled");
                            break;

                    }
                }
            }
        }
    }
}

/**
 * jeasyui控件對日期進行格式化
 * @param {any} date
 */
function myformatter(date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
}
/**
 * jeasyui控件對日期進行格式化
 * @param {any} s
 */
function myparser(s) {
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0], 10);
    var m = parseInt(ss[1], 10);
    var d = parseInt(ss[2], 10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
        return new Date(y, m - 1, d);
    } else {
        return new Date();
    }
}
//設定grid為空時顯示暫無任何資料
function setEmptyData(grid) {
    var colSpan = grid.datagrid('getColumnFields').length;
    var body = grid.data().datagrid.dc.body2;
    body.find('table tbody').append('<tr><td width="' + body.width() + '" style="height: 100px; text-align: center;background:white;border-color:white;" colspan="' + colSpan + '">暂无任何资料</td></tr>');
}